package com.ruoyi.basebill.task;

import com.ruoyi.basebill.domain.TWfzRemuneration;
import com.ruoyi.basebill.service.ITWfzRemunerationService;
import com.ruoyi.basebill.service.billIssue.IPushGzclService;
import com.ruoyi.basebill.service.exception.DataNullException;
import com.sun.org.apache.xpath.internal.operations.String;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @projectName: wfz
 * @package: com.ruoyi.basebill.task
 * @className: GzclTask
 * @author: Eric
 * @description: TODO
 * @date: 2023/3/6 10:29
 * @version: 1.0
 */
@Component("GzclTask")
public class GzclTask {
    @Autowired
    private ITWfzRemunerationService wfzRemunerationService;

    @Autowired
    private IPushGzclService pushGzclService;

    @Autowired
    private GzclTask gzclTask;

    public void pushGzcl(){
        //状态为审核状态，且FisCreateBill等于0的单据
        TWfzRemuneration tWfzRemuneration = new TWfzRemuneration();
        tWfzRemuneration.setFstate("AUDIT");
        tWfzRemuneration.setFiscreatebill(0l);
        List<TWfzRemuneration> tWfzRemunerations = wfzRemunerationService.selectTWfzRemunerationList(tWfzRemuneration);
        for (TWfzRemuneration wfzRemuneration : tWfzRemunerations) {

                Long fid = wfzRemuneration.getFid();
                TWfzRemuneration tWfzRemuneration1 = wfzRemunerationService.selectTWfzRemunerationByFid(fid);
            StringBuffer buffer = new StringBuffer();
            try {
                pushGzclService.pushGzff(tWfzRemuneration.getFid(),buffer);
                pushGzclService.pushGzft(tWfzRemuneration.getFid(),buffer);
                pushGzclService.pushGzjt(tWfzRemuneration.getFid(),buffer);
                tWfzRemuneration1.setFiscreatebill(1l);
                tWfzRemuneration1.setFreason("下发成功");
                wfzRemunerationService.updateTWfzRemuneration(tWfzRemuneration1);
            } catch (DataNullException e) {
                tWfzRemuneration1.setFiscreatebill(0l);
                tWfzRemuneration1.setFreason(e.getMessage());
                wfzRemunerationService.updateTWfzRemuneration(tWfzRemuneration1);
            }
        }
    }
    public void pushSbcl(){

    }

}
